public class ReverseWords {

    public static void main(String[] args) {
        ReverseWords reverseWords = new ReverseWords();
        System.out.println(reverseWords.reverseWords("EPY2giL"));
    }

    public String reverseWords(String s) {
        int n = s.length();
        char[] chars = s.toCharArray();
        StringBuffer temp = new StringBuffer();
        StringBuffer ans = new StringBuffer();
        for (int i = n - 1; i >= 0; i--) {
            if (chars[i] > 47) {
                temp.append(chars[i]);
            } else {
                if (temp.length() == 0) continue;
                ans.append(temp.reverse());
                ans.append(" ");
                temp = new StringBuffer();
            }
        }
        if (temp.length() != 0) {
            ans.append(temp.reverse());
            return ans.toString();
        }
        ans.deleteCharAt(ans.length() - 1);
        return ans.toString();
    }
}
